const fs = require('fs');
const util = require('util')
const myReadFile = util.promisify(fs.readFile);

// 一般方法
/*
fs.readFile('resources/1.html', (err, data1)=>{
    if (err) {
        throw err;
    }
    fs.readFile('resources/2.html', (err, data2)=>{
        if (err) {
            throw err;
        }
        fs.readFile('resources/3.html', (err, data3)=>{
            if (err) {
                throw err;
            }
            console.log(data1 + data2 + data3);
        })
    })
})*/

// async和await
async function main() {
    try {
        let data1 = await myReadFile('resources/1a.html');
        let data2 = await myReadFile('resources/2.html');
        let data3 = await myReadFile('resources/3.html');
        console.log(data1 + data2 + data3);
    } catch (e) {
        console.log(e.code);
    }
}

main();